#ifndef EVENT_H
#define EVENT_H

#include <QMetaType>
#include <QDateTime>
#include <QList>
#include <QPair>
#include "EventString.h"

class Event
{
public:
    enum WEEK_NUMBER
    {
        FIRST = 1,
        SECOND,
        THIRD,
        FOURTH,
        FIFTH,
        PENULT = int('P'),
        LAST = int('L'),
    };

    Event();
    Event(const EventString &eventStr);

    virtual ~Event() { ; }

    const EventString &eventString() const { return m_eventString; }
    const QDateTime &begin() const { return m_begin; }
    const QDateTime &end() const { return m_end; }
    const QString &name() const { return m_name; }
    const QString &definition() const { return m_definition; }
    const QString &imagePath() const { return m_imagePath; }
    const QString &iconPath() const { return m_iconPath; }
    const QString &color() const { return m_color; }
    bool isTop() const { return m_top; }
    bool isShown() const { return m_shown; }

    void setName(const QString &name);
    void setDefinition(const QString &definition);
    void setImagePath(const QString &file);
    void setIconPath(const QString &file);
    void setColor(const QString &color);
    void setShown(bool show);

    bool operator== (const Event &event) const;
    bool operator!= (const Event &event) const;
    friend QDataStream &operator<< (QDataStream &stream, const Event &event);
    friend QDataStream &operator>> (QDataStream &stream, Event &event);
    friend QDebug &operator<< (QDebug &debug, const Event &event);

    static QDate orthodoxEasterDate(int year);
    static QDate catholicEasterDate(int year);
    static QDate shiftEventDate(int year, int month, int week, int day, bool onlyFullWeek);

private:
    EventString m_eventString;
    QString m_name;
    QString m_definition;
    QDateTime m_begin;
    QDateTime m_end;
    QString m_imagePath;
    QString m_iconPath;
    QString m_color;
    bool m_top;
    bool m_shown;
};

QDataStream &operator<< (QDataStream &stream, const Event &event);
QDataStream &operator>> (QDataStream &stream, Event &event);
QDebug &operator<< (QDebug &debug, const Event &event);

Q_DECLARE_METATYPE(Event);

//class EventList : public QList<Event>
//{
//public:
//    EventList()
////        : current(0)
//        : current(-1)
//    {
//    }
//    int current;
////    const Event *current;
//    void append(const Event &t);
//    void prepend(const Event &t);
//    void clear();
//    void select(int i);

//private:
//    void replace(int i, const Event &t);
//    void removeAt(int i);
//    int removeAll(const Event &t);
//    bool removeOne(const Event &t);
//    Event takeAt(int i);
//    Event takeFirst();
//    Event takeLast();
//    void move(int from, int to);
//    void swap(int i, int j);
//};

typedef QList<Event> EventList_t;
Q_DECLARE_METATYPE(EventList_t);

//typedef QPair<QDateTime, EventList_t> DateTimeSchedule_t;
//typedef QList<DateTimeSchedule_t> EventSchedule_t;

// ************************************************************

class EventSchedule
{
public:
    EventSchedule() {}

    static EventList_t getMonthSchedule(int year, int month);
    static EventList_t getDateSchedule(const QDate &date);
    static EventList_t getNotifySchedule(const QDate &date);
};

// ************************************************************

class EventListParams
{
public:
    EventListParams(int year, int month);
    EventListParams(const QDate &date);

    const QString year() const { return m_year; }
    const QString currentYear() const { return m_currentYear; }
    const QString &month() const { return m_month; }
    const QString &week() const { return m_week; }
    const QString &fullWeek() const { return m_fullWeek; }
    const QString &dayOfWeek() const { return m_dayOfWeek; }
    const QString &dayOfMonth() const { return m_dayOfMonth; }
    const QString &dayOfYear() const { return m_dayOfYear; }
    const QString &endDayOfYear() const { return m_endDayOfYear; }
    const QString &dayFromOrthEaster() const { return m_dayFromOrthEaster; }
    const QString &dayFromCathEaster() const { return m_dayFromCathEaster; }

private:
    QString prepareYear(int year);
    QString prepareMonth(int month);
    QString prepareDay(int dayOfMonth);
    QString prepareDayOfYear(int dayOfMonth);

    QString m_year;
    QString m_currentYear;
    QString m_month;
    QString m_week;
    QString m_fullWeek;
    QString m_dayOfWeek;
    QString m_dayOfMonth;
    QString m_dayOfYear;
    QString m_endDayOfYear;
    QString m_dayFromOrthEaster;
    QString m_dayFromCathEaster;
};

#endif // EVENT_H

